//聚企业-首页
function jqy_i() {
    let mockData = Mock.mock({
        /*  'topimg': '@image(1920x360, #B0E2FF)',
          'hot': {
              'big': {
                  'id': 0,
                  'img': '@image(480x300, #B0E2FF)'
              },
              'shoplist|16': [{
                  'id|+1': 1,
                  'img': '@image(180x64, #d0E2ff)'
              }]
          },
          'qiyelist|8': [{
              'img': '@image(285x205, #FFC0CB)',
              'desc': '@ctitle(40, 50)',
              'lovelist|2': [{
                  'img': '@image(76x76, #B0E2FF)'
              }],
              'lovecount|1-9.2': 1,
              'shouc|0-1': 0,
              'name': '@ctitle(2, 5)',
          }]*/
    });
    new Vue({
        el: "#jqy_i",
        data() {
            return {
                'bannerlist': [],
                'hot': [],
                'qiyerecommenlist': null, //推荐企业
                'qiyelist': null, //特色企业
                'serverUrl': urlParam.domain(),
                'ruzhulist': [],
                'location': urlParam.location()
            }
        },
        methods: {
            getData() {
                /*  this.topimg = mockData.topimg;
                this.hot = mockData.hot;*/
                /* this.qiyelist = mockData.qiyelist;*/

                let that = this;
                //获取广告(轮播)
                axios.get(urlParam.domain() + '/api/advert/list', {
                    params: {
                        position: urlParam.jqiyePosition()
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        if (response.data.data != undefined) {
                            //console.log(response.data.data);
                            that.bannerlist = response.data.data;
                            //console.log("bannerlist" + response.data.data);
                        }
                    }

                });
                //获取广告(企业最新入驻)
                axios.get(urlParam.domain() + '/api/advert/list', {
                    params: {
                        position: urlParam.jqiyeRuZhuPosition()
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        if (response.data.data != undefined) {
                            //console.log(response.data.data);
                            that.ruzhulist = response.data.data;
                            //console.log("bannerlist" + response.data.data);
                        }
                    }

                });
                axios.get(urlParam.domain() + '/api/company/company/getCompanys', {
                    params: {
                        token: urlParam.token()
                    }
                }).then(function(response) {
                    if (response.data.data != undefined) {
                        that.hot = response.data.data.latestCompanys;
                        //console.log(that.hot[0]);
                        that.qiyerecommenlist = response.data.data.recommendationCompanyList;
                        that.qiyelist = response.data.data.featureCompanyList;
                        that.serverUrl = response.data.data.serverUrl;
                        //console.log(that.qiyerecommenlist);
                        //console.log(that.qiyelist);
                    }
                });
            },

            delFollow(data) {
                var that = this;
                axios.get(urlParam.domain() + '/api/company/companyFollow/delete', {
                    params: {
                        ids: data + ",",
                        token: urlParam.token()
                    }
                }).then(function(response) {
                    that.$message({
                        message: "取消关注成功",
                        type: "success"
                    });
                    that.getData();
                });
            },
            addFollow(data) {
                if (urlParam.token() == null || urlParam.token() == "") {
                    this.$message({
                        message: "请先登录",
                        type: "warning"
                    });
                    return;
                }
                var that = this;
                axios({
                    method: "post",
                    url: urlParam.domain() + '/api/company/companyFollow/add',
                    data: {
                        token: urlParam.token(),
                        companyId: data
                    },
                    transformRequest: [function(data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(function(response) {
                    that.$message({
                        message: "关注成功",
                        type: "success"
                    });
                    that.getData();
                });
            }
        },
        created() {

            this.getData();
        },
        components: {
            'common-swiper': common_swiper
        }
    });
};

//聚企业_企业详情
function jqiye_details() {
    let mockData = Mock.mock({
        'companyLogo': '@image(100x100, @color)',
        "goods|5": [{
            "img": "@image(210x210,@color)",
            "price|99-999.2": 0,
            "name": "@ctitle(6,12)",
            "href": "#",
        }],
        "pinpai|6-12": [{
            "img": "@image(180x64,@color)",
            "name": "@ctitle(6,12)",
            "href": "#",
        }]
    });
    new Vue({
        el: "#jqiye_details",
        data() {
            return {
                /*companyLogo: "", //企业logo
                companyName: "南京伯尼奥服饰有限公司",
                companyTel: "025-85508026",
                companyAddress: "南京市建邺区奥体大街128号",
                companyNum: "1.3万", //关注人数
                range: "销售服装、通讯设备、计算机软件及辅助设备、工艺品、日用品、家用电器；经济贸易咨询；货物进出口。（企业依法自主选择经营项目，开展经营活动；依法须经批准的项目，经相 关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。", //主营范围
                introduce: "销售服装、通讯设备、计算机软件及辅助设备、工艺品、日用品、家用电器；经济贸易咨询；货物进出口。（企业依法自主选择经营项目，开展经营活动；依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。", //企业介绍
                goods: [], //商品展示
                pinpai: [], //品牌展示*/
                company: {
                    businessLicense: {},
                    brands: {},
                    codeCertificate: {
                        organizationCode:''
                    }
                },
                location: '',
                id: 0
            }
        },
        methods: {
            getData() {
                /* this.companyLogo = mockData.companyLogo;
                 this.goods = mockData.goods;
                 this.pinpai = mockData.pinpai;*/

                var that = this;
                this.id = globalAPI.getRequest()["id"];
                if(this.id == undefined){
                    this.id = 2
                }
                axios.get(urlParam.domain() + '/api/company/company/detail/?id=' + this.id, {
                    params: {
                        token: urlParam.token()
                    }
                }).then(function(response) {
                    console.log(response.data.data);
                    that.company = response.data.data;
                });

            },
            delFollow(_id) {
                var that = this;
                axios.get(urlParam.domain() + '/api/company/companyFollow/delete', {
                    params: {
                        ids: _id + ",",
                        token: urlParam.token()
                    }
                }).then(function(response) {

                    that.getData();
                });
            },
            addFollow(_id) {
                if (urlParam.token() == null || urlParam.token() == "") {
                    this.$message({
                        message: "请先登录",
                        type: "warning"
                    });
                    return;
                }
                var that = this;
                axios({
                    method: "post",
                    url: urlParam.domain() + '/api/company/companyFollow/add',
                    data: {
                        token: urlParam.token(),
                        companyId: _id
                    },
                    transformRequest: [function(data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(function(response) {
                    that.getData();
                });
            }
        },
        created() {
            //console.log(location);
            this.getData();
        },
        mounted() {

        },
        components: {

        }
    });
}

//聚企业-企业列表
function jqy_list() {
    let mockData = Mock.mock({
        'list|10': [{
            'brandId|+1': 1,
            'brandName': '@ctitle(2,4)',
            'logo': '@image(136x40,#abcdec)',
            'lovecount|10-20.2': 10
        }]
        /*'qiyetype|5': [{
            'labelName': '@ctitle(2,4)',
            'labelId|+1': 1,
        }]*/
    });
    new Vue({
        el: "#jqy_list",
        data() {
            return {
                where: {
                    daterange: '',
                    labelId: ''
                },
                'crumblist': {
                    'crumb': [{
                        'href': '',
                        'text': '首页'
                    }, {
                        'href': '',
                        'text': '聚企业'
                    }],
                    'arr': [{
                            'title': '企业类型',
                            'name': "请选择企业类型"
                        }] //显示选中的搜索条件
                },
                'list': null,
                'catelist': null,
                'pageNo': 1,
                'pageSize': 12,
                'total': 1,
                'startFoundTime': null,
                'endFoundTime': null,
                'startAge': null,
                'endAge': null,
                'labelId': null,
                'searchtext': null,
                'location':urlParam.location(),
                'qiyetype':[],
                'href':decodeURI(window.location.href),
                type:0,//1 表示是推荐企业  2 特色企业
            }
        },
        methods: {
            getData() {
                //this.list = mockData.list;
                //this.qiyetype = mockData.qiyetype; //企业类型
                //this.getLabelList();
                //this.getBrandList();
            //console.log(this.href);

            //判断是页面的头部的搜索框搜索跳转页面或者是聚企业首页点击更多跳转
            if(this.href.indexOf("?")!=-1){
                //页面头部搜索跳转
                if(this.href.split("?")[1].indexOf("type")==-1){
                    var name=globalAPI.getRequest()["q"];
                    console.log(name);
                    console.log(globalAPI.getRequest());
                    //return;
                    let that=this;
                    axios.get(urlParam.domain()+"/api/company/company/listPC",{
                        params:{
                            token:urlParam.token(),
                            name:name,
                            pageNo: that.pageNo,
                            pageSize: 12,
                        }
                    }).then(function (response) {
                        that.list=response.data.data.list;
                        console.log("-----1")
                        console.log(that.list)
                        console.log("-----1")
                        that.href=that.href.substring(0,that.href.indexOf("?"))
                        that.$message({
                            message:"请求成功",
                            type:"success"
                        })
                        /*console.log(response.data.data.list);
                        console.log(that.list);*/
                    })
                }else if(this.href.split("?")[1].indexOf("type")!=-1){
                    var type=this.href.split("=")[1];
                    //console.log(type);
                    let that=this;
                    axios.get(urlParam.domain() + '/api/company/company/getCompanys', {
                        params: {
                            token: urlParam.token()
                        }
                    }).then(function(response) {
                        if (response.data.data != undefined) {

                            if(type==1){
                                that.list = response.data.data.recommendationCompanyList;
                            }else{
                                that.list = response.data.data.featureCompanyList;
                            }
                            console.log("-----2")
                            console.log(that.list)
                            console.log("-----2")
                        }
                    });
                }

            }
            //企业类型
            let that=this;
            //this.companyTypeList = mockData.companyTypeList; //企业类型 下拉框的选项
            axios.get(urlParam.domain()+'/api/dict/query',{
                params:{
                    name:'企业类型'
                }
            }).then(function (response) {
                if(response.data.code==1){
                    if(response.data.data!=undefined){
                        console.log(response.data.data);
                        for (var i = 0; i < response.data.data.length; i++) {
                            var obj = response.data.data[i];
                            var val  = {
                                labelName:obj .name,
                                labelId:obj.id
                            }
                           that.qiyetype.push(val);
                        }
                    }
                }
            })
            },
            watch:{

            },
            //企业类型选择
            setLabel(val) {
                this.where.labelId = val.labelId;
                //console.log(this.where.labelId);
                if( this.crumblist.arr.length==0){
                    var obj={
                        title: "企业类型",
                        name:val.labelName
                    }
                    this.crumblist.arr.push(obj) ;
                }else{
                    this.crumblist.arr[0].name=val.labelName;
                }
            },
            addGuanzhu(data,index) {
                //alert('点我关注');
                if (urlParam.token() == undefined || urlParam.token() == '') {
                    alert('请先登录');
                    return;
                }
                /*console.log("abc-----")
                console.log(data.followId)*/
                if(data.followId!=null&&data.followId!=''||data.followId==0){
                    alert("已关注");
                    return;
                }
                var that = this;
                axios({
                    method: "post",
                    url: urlParam.domain() + '/api/company/companyFollow/add',
                    data: {
                        token: urlParam.token(),
                        companyId: data.id
                    },
                    transformRequest: [function(data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(function(response) {
                    that.$message({
                        message: "关注成功",
                        type: "success"
                    });
                    that.list[index].followId=0;
                })
            },
            getwhere() {
                //alert(this.where);
                //console.log(that.where.daterange);
                if( this.crumblist.arr.length==0){
                    that.where.labelId=null;
                }
                let that=this;
                var auditpassTime="";
                var applicationTime="";
                if(that.where.daterange!=null&&that.where.daterange!=""){
                    auditpassTime=that.where.daterange[0]+" 00:00:00";
                    applicationTime=that.where.daterange[1]+" 23:59:59";
                    /*console.log(auditpassTime);
                    console.log(applicationTime);*/
                }

                axios.get(urlParam.domain()+"/api/company/company/listPC",{
                    params:{
                        token:urlParam.token(),
                        auditpassTime:auditpassTime,
                        applicationTime:applicationTime,
                        categoryId:that.where.labelId,
                        pageNo: that.pageNo,
                        pageSize: 9,
                    }
                }).then(function (response) {
                    that.$message({
                        message:"请求成功",
                       type:"success"
                    }),
                    that.list=response.data.data.list;
                    console.log("-----3")
                    console.log(that.list)
                    console.log("-----3")
                    /*console.log(response.data.data.list);
                    console.log(that.list);*/
                })
            },
            getCrumblist(data) {
                this.crumblist = data;
                this.labelId = null;
                this.where.cateobj = {};
                 //this.getBrandList();
            },
            getPage(data) {
                this.pageNo = data;

                this.getData();
            },

            //发送搜索条件 获取信息列表
            getCompanyList() {
                let that = this;
                axios.get(urlParam.domain() + '/api/company/company/listPC', {
                    params: {
                        token:urlParam.token(),
                        pageNo: that.pageNo,
                        pageSize: that.pageSize,
                        name: that.searchtext
                    }
                }).then(function(response) {
                    if (response.data.data != undefined) {
                        that.list = response.data.data.list;
                        console.log(that.list);
                        that.total = Math.ceil(response.data.data.total / that.pageSize);
                    }
                });
            },
            //获取顶部搜索框内容
            getSearchTxt(val) {
                this.searchtext = val;
                //console.log()
                //获取数据
                this.getCompanyList();
            }
        },
        created() {
            this.getData();
        }
    });
}